<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head>
        <title>Carrello</title>
        <ui:include src="Header.xhtml"/>

    </h:head>
    <h:body>
        <div>
            <h:form>
                <p:dataTable id="table" var="p" value="#{carrelloManagerBean.prodotti}" emptyMessage="Non ci sono elementi nel carrello">
                    <f:facet name="header">
                        <p:outputLabel value="Riepilogo Carrello"/>
                    </f:facet>
                    <p:column headerText="Foto">
                        <p:graphicImage value="#{p.foto}" width="100" height="80"/>
                    </p:column>

                    <p:column headerText="Nome Prodotto">
                        <p:outputLabel value="#{p.nome}"/>
                    </p:column>

                    <p:column headerText="Quantità">
                        <p:outputLabel value="#{carrelloManagerBean.getQuantitaProdotto(p)}   "/>
                        <p:commandButton value="+" style="width: 40px" action="#{carrelloManagerBean.aggiungiProdottoAlCarrello(p.id,1)}" update="table"/>
                        <p:commandButton value="-" style="width: 40px" action="#{carrelloManagerBean.rimuoviQuantitaDalCarrello(p.id, 1)}" update="table"/>
                    </p:column>

                    <p:column headerText="Prezzo">
                        <h:outputFormat value="#{p.prezzo}">
                            <f:convertNumber minFractionDigits="2" maxFractionDigits="2"/>
                        </h:outputFormat> €
                    </p:column>

                    <p:column headerText="SubTotale">
                        <h:outputFormat value="#{p.prezzo * carrelloManagerBean.getQuantitaProdotto(p)}">
                            <f:convertNumber minFractionDigits="2" maxFractionDigits="2"/>
                        </h:outputFormat> €
                    </p:column>

                    <p:column >

                        <p:commandButton value="Rimuovi" action="#{carrelloManagerBean.rimuoviProdottoDalCarrello(p.id)}" update="table"/>
                    </p:column>

                </p:dataTable>

                <p:button value="Acquista"  disabled="#{!redirect.accesso }" outcome="/Acquisto.xhtml"/>


            </h:form>

        </div>
<ui:include src="Footer.xhtml"/>  
    </h:body>
</html>

